// pages/notice/notice.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    c_id:2,
    currentBtn:0,
    flag:0
  },
  
  onLoad(){
    this.loadCom()
    this.loadDetail()
  },

  switchList: function (e) {
    console.log(e)
    wx.showLoading({
      title: '加载中...',
    })
    this.setData({
      c_id: e.currentTarget.dataset.current
    })
    setTimeout(() => {
      wx.hideLoading()
    }, 500)
    this.loadDetail()
  },

  changBtn(e){
    this.setData({
      currentBtn: e.currentTarget.dataset.status
    })
  },

  loadCom(){
    let access_token = wx.getStorageSync('access_token')
    wx.request({
      url: 'https://baokang.wshoto.com/wx/comlist',
      data: {
        access_token: access_token,
      },
      success: (res) => {
        console.log(res)
        if(res.data.code >= 500){
          app.getLogin().then(function(){
            console.log('二次登录。。。')
          })
        } 
        else if (res.data.code == 1) {
          this.setData({
            noticeList: res.data.list
          })
        }
      }
    })
  },

  loadDetail(){
    wx.showLoading({
      title: '加载中...',
    })
    let c_id = this.data.c_id
    let access_token = wx.getStorageSync('access_token')
    wx.request({
      url: 'https://baokang.wshoto.com/wx/comdetail',
      data: {
        access_token: access_token,
        c_id:c_id
      },
      success: (res) => {
        console.log(res)
        if (res.data.code == 1) {
          this.setData({
            notice:res.data.info.notice_list[0].content,
            introduction:res.data.info.c_introduce,
            flag:1
          })
        }
      },
      complete:(res)=>{
        wx.hideLoading()
      }
    })
  }
})